import 'reflect-metadata';
import {Resolver} from "./resolver";
import {resource} from "./resource";
import {field} from "./field";
import {StringType} from "./definition";
import {SequelizeAdapter} from "./adapter";

import {Sequelize} from "sequelize";


const sequelize = new Sequelize({
  dialect: 'sqlite',
  storage: 'db.sqlite'
});
sequelize.sync();

const sequelizeAdapter = new SequelizeAdapter(sequelize);

@resource({adapter: sequelizeAdapter})
export class User {
  @field({type: StringType})
  firstName: string;

  @field({type: StringType})
  lastName: string;
}

const resolver = new Resolver();

resolver.register([
  User,
]);


console.log(JSON.stringify(resolver.toSchema(), null, 2));

resolver.find('User', { where: { id: 2 } }).then(data => {
  console.log(JSON.stringify(data, null, 2));
  return data;
});

resolver.findById('User', {id: 1}).then(data => {
  console.log(JSON.stringify(data, null, 2));
  return data;
});
